//! 从JSON文件加载配置的简单示例

use unichar::Unichar;

fn main() {
    println!("=== 从JSON文件加载配置示例 ===\n");

    // 创建Unichar实例
    let mut unichar = Unichar::new();
    
    // 从JSON文件加载配置
    match unichar.load_config_from_file("examples/config.json") {
        Ok(_) => {
            println!("✅ 配置加载成功!");
            println!("📋 当前配置:");
            println!("   样式: {:?}", unichar.config().style);
            println!("   启用颜色: {}", unichar.config().enable_color);
            println!("   启用ANSI: {}", unichar.config().enable_ansi);
            println!("   别名数量: {}", unichar.config().aliases.len());
            println!();

            // 测试内置字符
            println!("🎨 内置字符测试:");
            let builtin_chars = ["success", "error", "warning", "info", "star", "heart"];
            for char_name in builtin_chars {
                if let Some(char) = unichar.get(char_name) {
                    println!("   {}: {}", char_name, char);
                }
            }
            println!();

            // 测试别名
            println!("🏷️ 别名测试:");
            let aliases = ["ok", "fail", "warn", "check", "cross"];
            for alias in aliases {
                if let Some(char) = unichar.get(alias) {
                    println!("   {} -> {}: {}", alias, unichar.config().aliases.get(alias).unwrap_or(&alias.to_string()), char);
                }
            }
            println!();

            // 测试字符串格式化
            println!("📝 字符串格式化测试:");
            let templates = [
                "操作结果: {ok} 或 {fail}",
                "状态: {warn} 用户: {info}",
                "评分: {star} 喜欢: {heart}",
                "方向: {arrow_r} 或 {arrow_l}"
            ];
            
            for template in templates {
                let result = unichar.format(template);
                println!("   {} -> {}", template, result);
            }
            println!();

            // 显示统计信息
            println!("📊 统计信息:");
            let stats = unichar.get_stats();
            println!("   总字符数: {}", stats.total_characters);
            println!("   别名数: {}", stats.aliases_count);
            println!("   各样式支持数量:");
            for (style, count) in stats.style_counts {
                println!("     {:?}: {}", style, count);
            }

        }
        Err(e) => {
            println!("❌ 配置加载失败: {}", e);
            println!("请确保 examples/config.json 文件存在");
        }
    }
}
